#include <stdio.h>
#include <stdlib.h>



typedef struct linknode
{
    int data;
    struct linknode *next;
}link_node;

link_node *creat()
{
    link_node *H=(link_node *)malloc(sizeof(link_node));
    H->data=0;
    H->next=NULL;

    return H;
}

int insert(link_node *H,int mydata)
{
    link_node *p=(link_node *)malloc(sizeof(link_node));
    while(H->next!=NULL)
    {   
        H=H->next;                                                                                                                                
    }   
    p->next=NULL;
    H->next=p;
    p->data=mydata;

    return 0;
}

int view(link_node *H)
{
    link_node *p=H;
    while(p->next!=NULL)
    {
        p=p->next;
        printf("%d ",p->data);
    }
    putchar(10);

    return 0;
}         

void nodeopra(link_node *H)
{
	link_node *p=H;
	if(H->next==NULL)
	{
		printf("H is empty\n");
	}
	while(p->next->next!=NULL)
	{
		p=p->next;
	}
	link_node *q=p->next;
	p->next=NULL;
	q->next=H->next;
	H->next=q;
	return ;
}

int main(int argc, const char *argv[])
{
	link_node *H=creat();
	insert(H,1);
	insert(H,3);
	insert(H,5);
	insert(H,7);
	insert(H,9);
	view(H);
	
	int num=0;
	scanf("%d",&num);
	for(int i=0;i<num;i++)
	{
		nodeopra(H);
	}
	view(H);
	return 0;
}
